package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-05-18 16:46
 */
public class 题库_0011_盛最多水的容器 {

  static
  class Solution {
    public int maxArea(int[] height) {
      if (height == null || height.length < 2) {
        return 0;
      }
      int left = 0;
      int right = height.length - 1;
      int answer = 0;
      while (left < right) {
        int curHeight = Math.min(height[left], height[right]);
        answer = Math.max(answer, curHeight * (right - left));
        if (height[left] < height[right]) {
          ++left;
        } else {
          --right;
        }
      }
      return answer;
    }
  }

}
